from django.db import models

# Create your models here.

#贴吧
class Post(models.Model):
    #和用户关联
    user = models.ForeignKey('user.UserId',on_delete = models.CASCADE)

    #贴吧名
    post_name = models.CharField(max_length = 50)

    #贴吧介绍内容
    post_info = models.CharField(max_length = 100)

    #贴吧创建时间,不可改变
    create_date = models.DateField('不可改变','2',auto_now_add = True)

    def __str__(self):

        return self.tieba
'''    
#载入图片https://www.cnblogs.com/kay-lee/p/8638484.html
class Test(models.Model):
    post = models.ForeignKey(Post,on_delete = models.CASCADE)

    #上传图片字段
    image = models.ImageField(upload_to='postimg')
'''
#贴吧内的标题
class Title(models.Model):
    #和用户及标题关联
    user = models.ForeignKey('user.UserId',on_delete = models.CASCADE)
    post = models.ForeignKey(Post,on_delete = models.CASCADE)

    #用户的标题
    user_title = models.CharField(max_length=50)

    #标题创建时间
    create_date = models.DateTimeField('改变时间',auto_now = True)
    def __str__(self):
        
        return self.user_title
    
#标题内容
class Info(models.Model):
    #和标题关联
    title = models.ForeignKey(Title,on_delete = models.CASCADE)
    user = models.ForeignKey('user.UserId',on_delete = models.CASCADE)

    #标题内容
    title_info = models.CharField(max_length = 500)

    #载入内容中图片
    #image = models.ImageField(upload_to='img')
    
    #评论时间
    comment_date = models.DateTimeField('改变时间',auto_now = True)
    def __str__(self):

        return self.title_info
















































    
